package com.example.controller;

import com.example.common.Result;
import com.example.entity.Admin;
import com.example.entity.User;
import com.example.service.AdminService;
import com.example.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 用户接口
 **/
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("/add")
    Result add(@RequestBody User user){
        userService.add(user);
        return Result.success();
    }

    //查询数据及条件查询
    @GetMapping("/selectPage")
    Result selectPage(User user, @RequestParam Integer pageNum, @RequestParam Integer pageSize){
        PageInfo<User> pageInfo = userService.selectPage(user, pageNum, pageSize);
        return Result.success(pageInfo);
    }

    //更新员工信息
    @PutMapping("/update")
    Result update(@RequestBody User user){
        userService.updateById(user);
        return Result.success();
    }

    //删除员工数据
    @DeleteMapping("/delete/{id}")
    Result delete(@PathVariable Integer id){
        userService.delete(id);
        return Result.success();
    }
    //批量删除员工
    @DeleteMapping("/delete/batch")
    Result deleteBatch(@RequestBody List<Integer> ids){
        for (Integer id : ids){
            userService.delete(id);
        }
        return Result.success();
    }

}